
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/31/2011 23:26:57
-- Generated from EDMX file: D:\Desktop\CVsharp\CVsharp.Models\Entities\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [CVsharpDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CategoryLog_Category]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CategoryLog] DROP CONSTRAINT [FK_CategoryLog_Category];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoryLog_Log]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CategoryLog] DROP CONSTRAINT [FK_CategoryLog_Log];
GO
IF OBJECT_ID(N'[dbo].[FK_sysRoleInActionPermission_sysActionPermission]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[sysRoleInActionPermission] DROP CONSTRAINT [FK_sysRoleInActionPermission_sysActionPermission];
GO
IF OBJECT_ID(N'[dbo].[FK_sysUserInActionPermission_sysActionPermission]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[sysUserInActionPermission] DROP CONSTRAINT [FK_sysUserInActionPermission_sysActionPermission];
GO
IF OBJECT_ID(N'[dbo].[FK_sysUsersInMnuNode_sysMenuNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[sysUsersInMnuNode] DROP CONSTRAINT [FK_sysUsersInMnuNode_sysMenuNode];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Category]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Category];
GO
IF OBJECT_ID(N'[dbo].[CategoryLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CategoryLog];
GO
IF OBJECT_ID(N'[dbo].[CommonLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommonLog];
GO
IF OBJECT_ID(N'[dbo].[Log]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Log];
GO
IF OBJECT_ID(N'[dbo].[sysActionPermission]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysActionPermission];
GO
IF OBJECT_ID(N'[dbo].[sysChangeLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysChangeLog];
GO
IF OBJECT_ID(N'[dbo].[sysDict]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysDict];
GO
IF OBJECT_ID(N'[dbo].[sysLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysLog];
GO
IF OBJECT_ID(N'[dbo].[sysMenuNode]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysMenuNode];
GO
IF OBJECT_ID(N'[dbo].[sysRoleInActionPermission]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysRoleInActionPermission];
GO
IF OBJECT_ID(N'[dbo].[sysUserInActionPermission]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysUserInActionPermission];
GO
IF OBJECT_ID(N'[dbo].[sysUserInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysUserInfo];
GO
IF OBJECT_ID(N'[dbo].[sysUsersInMnuNode]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysUsersInMnuNode];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'sysActionPermission'
CREATE TABLE [dbo].[sysActionPermission] (
    [ActionPermissionId] uniqueidentifier  NOT NULL,
    [ActionName] nvarchar(50)  NOT NULL,
    [ControllerName] nvarchar(50)  NOT NULL,
    [Description] nvarchar(200)  NOT NULL,
    [IsViewPage] bit  NOT NULL
);
GO

-- Creating table 'sysChangeLog'
CREATE TABLE [dbo].[sysChangeLog] (
    [ChangeLogID] uniqueidentifier  NOT NULL,
    [ChangeContent] nvarchar(1024)  NOT NULL,
    [GreateTime] datetime  NOT NULL,
    [Version] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'sysDict'
CREATE TABLE [dbo].[sysDict] (
    [DictID] uniqueidentifier  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [ValueInt] int  NULL,
    [ValueString] nvarchar(50)  NULL,
    [Sort] int  NULL,
    [Parentid] uniqueidentifier  NULL,
    [State] int  NULL
);
GO

-- Creating table 'sysLog'
CREATE TABLE [dbo].[sysLog] (
    [LogID] uniqueidentifier  NOT NULL,
    [GreateTime] datetime  NULL,
    [UserName] nvarchar(50)  NULL,
    [Type] nvarchar(50)  NULL,
    [LogContent] nvarchar(max)  NULL
);
GO

-- Creating table 'sysMenuNode'
CREATE TABLE [dbo].[sysMenuNode] (
    [MenuNodeId] uniqueidentifier  NOT NULL,
    [Name] nvarchar(30)  NOT NULL,
    [TreeCode] nvarchar(max)  NULL,
    [NodeType] int  NULL,
    [NodeLevel] int  NULL,
    [ControllerName] nvarchar(50)  NULL,
    [ActionName] nvarchar(50)  NULL,
    [SmallIcon] nvarchar(50)  NULL,
    [BigIcon] nvarchar(50)  NULL,
    [IsPage] bit  NULL,
    [Description] nvarchar(200)  NULL,
    [Sort] int  NOT NULL,
    [ParentId] int  NOT NULL
);
GO

-- Creating table 'sysRoleInActionPermission'
CREATE TABLE [dbo].[sysRoleInActionPermission] (
    [Id] uniqueidentifier  NOT NULL,
    [RoleName] nvarchar(256)  NOT NULL,
    [ActionPermissionId] uniqueidentifier  NOT NULL,
    [Type] int  NOT NULL
);
GO

-- Creating table 'sysUserInActionPermission'
CREATE TABLE [dbo].[sysUserInActionPermission] (
    [Id] uniqueidentifier  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL,
    [ActionPermissionId] uniqueidentifier  NOT NULL,
    [Type] int  NOT NULL
);
GO

-- Creating table 'sysUserInfo'
CREATE TABLE [dbo].[sysUserInfo] (
    [UserId] uniqueidentifier  NOT NULL,
    [State] int  NOT NULL,
    [WorkState] int  NOT NULL
);
GO

-- Creating table 'sysUsersInMnuNode'
CREATE TABLE [dbo].[sysUsersInMnuNode] (
    [Id] uniqueidentifier  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL,
    [MenuNodeId] uniqueidentifier  NOT NULL,
    [Type] int  NOT NULL
);
GO

-- Creating table 'Category'
CREATE TABLE [dbo].[Category] (
    [CategoryID] int IDENTITY(1,1) NOT NULL,
    [CategoryName] nvarchar(64)  NOT NULL
);
GO

-- Creating table 'CategoryLog'
CREATE TABLE [dbo].[CategoryLog] (
    [CategoryLogID] int IDENTITY(1,1) NOT NULL,
    [CategoryID] int  NOT NULL,
    [LogID] int  NOT NULL
);
GO

-- Creating table 'Log'
CREATE TABLE [dbo].[Log] (
    [LogID] int IDENTITY(1,1) NOT NULL,
    [EventID] int  NULL,
    [Priority] int  NOT NULL,
    [Severity] nvarchar(32)  NOT NULL,
    [Title] nvarchar(256)  NOT NULL,
    [Timestamp] datetime  NOT NULL,
    [MachineName] nvarchar(32)  NOT NULL,
    [AppDomainName] nvarchar(512)  NOT NULL,
    [ProcessID] nvarchar(256)  NOT NULL,
    [ProcessName] nvarchar(512)  NOT NULL,
    [ThreadName] nvarchar(512)  NULL,
    [Win32ThreadId] nvarchar(128)  NULL,
    [Message] nvarchar(1500)  NULL,
    [FormattedMessage] nvarchar(max)  NULL
);
GO

-- Creating table 'CommonLog'
CREATE TABLE [dbo].[CommonLog] (
    [id] bigint IDENTITY(1,1) NOT NULL,
    [logdate] datetime  NOT NULL,
    [actionname] nvarchar(50)  NOT NULL,
    [controllername] nvarchar(50)  NOT NULL,
    [theuser] nvarchar(50)  NOT NULL,
    [logtype] nvarchar(50)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ActionPermissionId] in table 'sysActionPermission'
ALTER TABLE [dbo].[sysActionPermission]
ADD CONSTRAINT [PK_sysActionPermission]
    PRIMARY KEY CLUSTERED ([ActionPermissionId] ASC);
GO

-- Creating primary key on [ChangeLogID] in table 'sysChangeLog'
ALTER TABLE [dbo].[sysChangeLog]
ADD CONSTRAINT [PK_sysChangeLog]
    PRIMARY KEY CLUSTERED ([ChangeLogID] ASC);
GO

-- Creating primary key on [DictID] in table 'sysDict'
ALTER TABLE [dbo].[sysDict]
ADD CONSTRAINT [PK_sysDict]
    PRIMARY KEY CLUSTERED ([DictID] ASC);
GO

-- Creating primary key on [LogID] in table 'sysLog'
ALTER TABLE [dbo].[sysLog]
ADD CONSTRAINT [PK_sysLog]
    PRIMARY KEY CLUSTERED ([LogID] ASC);
GO

-- Creating primary key on [MenuNodeId] in table 'sysMenuNode'
ALTER TABLE [dbo].[sysMenuNode]
ADD CONSTRAINT [PK_sysMenuNode]
    PRIMARY KEY CLUSTERED ([MenuNodeId] ASC);
GO

-- Creating primary key on [Id] in table 'sysRoleInActionPermission'
ALTER TABLE [dbo].[sysRoleInActionPermission]
ADD CONSTRAINT [PK_sysRoleInActionPermission]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'sysUserInActionPermission'
ALTER TABLE [dbo].[sysUserInActionPermission]
ADD CONSTRAINT [PK_sysUserInActionPermission]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [UserId] in table 'sysUserInfo'
ALTER TABLE [dbo].[sysUserInfo]
ADD CONSTRAINT [PK_sysUserInfo]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Id] in table 'sysUsersInMnuNode'
ALTER TABLE [dbo].[sysUsersInMnuNode]
ADD CONSTRAINT [PK_sysUsersInMnuNode]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [CategoryID] in table 'Category'
ALTER TABLE [dbo].[Category]
ADD CONSTRAINT [PK_Category]
    PRIMARY KEY CLUSTERED ([CategoryID] ASC);
GO

-- Creating primary key on [CategoryLogID] in table 'CategoryLog'
ALTER TABLE [dbo].[CategoryLog]
ADD CONSTRAINT [PK_CategoryLog]
    PRIMARY KEY CLUSTERED ([CategoryLogID] ASC);
GO

-- Creating primary key on [LogID] in table 'Log'
ALTER TABLE [dbo].[Log]
ADD CONSTRAINT [PK_Log]
    PRIMARY KEY CLUSTERED ([LogID] ASC);
GO

-- Creating primary key on [id] in table 'CommonLog'
ALTER TABLE [dbo].[CommonLog]
ADD CONSTRAINT [PK_CommonLog]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ActionPermissionId] in table 'sysRoleInActionPermission'
ALTER TABLE [dbo].[sysRoleInActionPermission]
ADD CONSTRAINT [FK_sysRoleInActionPermission_sysActionPermission]
    FOREIGN KEY ([ActionPermissionId])
    REFERENCES [dbo].[sysActionPermission]
        ([ActionPermissionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_sysRoleInActionPermission_sysActionPermission'
CREATE INDEX [IX_FK_sysRoleInActionPermission_sysActionPermission]
ON [dbo].[sysRoleInActionPermission]
    ([ActionPermissionId]);
GO

-- Creating foreign key on [ActionPermissionId] in table 'sysUserInActionPermission'
ALTER TABLE [dbo].[sysUserInActionPermission]
ADD CONSTRAINT [FK_sysUserInActionPermission_sysActionPermission]
    FOREIGN KEY ([ActionPermissionId])
    REFERENCES [dbo].[sysActionPermission]
        ([ActionPermissionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_sysUserInActionPermission_sysActionPermission'
CREATE INDEX [IX_FK_sysUserInActionPermission_sysActionPermission]
ON [dbo].[sysUserInActionPermission]
    ([ActionPermissionId]);
GO

-- Creating foreign key on [MenuNodeId] in table 'sysUsersInMnuNode'
ALTER TABLE [dbo].[sysUsersInMnuNode]
ADD CONSTRAINT [FK_sysUsersInMnuNode_sysMenuNode]
    FOREIGN KEY ([MenuNodeId])
    REFERENCES [dbo].[sysMenuNode]
        ([MenuNodeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_sysUsersInMnuNode_sysMenuNode'
CREATE INDEX [IX_FK_sysUsersInMnuNode_sysMenuNode]
ON [dbo].[sysUsersInMnuNode]
    ([MenuNodeId]);
GO

-- Creating foreign key on [CategoryID] in table 'CategoryLog'
ALTER TABLE [dbo].[CategoryLog]
ADD CONSTRAINT [FK_CategoryLog_Category]
    FOREIGN KEY ([CategoryID])
    REFERENCES [dbo].[Category]
        ([CategoryID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryLog_Category'
CREATE INDEX [IX_FK_CategoryLog_Category]
ON [dbo].[CategoryLog]
    ([CategoryID]);
GO

-- Creating foreign key on [LogID] in table 'CategoryLog'
ALTER TABLE [dbo].[CategoryLog]
ADD CONSTRAINT [FK_CategoryLog_Log]
    FOREIGN KEY ([LogID])
    REFERENCES [dbo].[Log]
        ([LogID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryLog_Log'
CREATE INDEX [IX_FK_CategoryLog_Log]
ON [dbo].[CategoryLog]
    ([LogID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------